import request from '@/utils/http/request'


// 医院的上班时间
interface BookingRuleDate {
    cycle: number,
    releaseTime: string,
    stopTime: string,
    quitDay: number,
    quitTime: string,
    rule: string[],
}

// 医院的信息
interface paramInfoData {
    hostypeString: string,
    fullAddress: string
}

// 医院的详细信息
interface hospitalDetailData {
    id: string,
    param: paramInfoData,
    hoscode: string,
    hosname: string,
    hostype: string,
    provinceCode: string,
    cityCode: string,
    districtCode: string,
    logoData: string,
    intro: string,
    status: number,
}

// 定义医院详情
type HospitalDetailData = {
    bookingRule: BookingRuleDate
    hospital: hospitalDetailData
}

// 排班列表
export type WordDate = {
    id: string,
    isDeleted: number,
    createTime: string,
    updateTime: string,
    param: {
        dayOfWeek: string,
        depname: string,
        hosname: string
    },
    hoscode: string,
    depcode: string,
    title: string,
    docname: string,
    skill: string,
    workDate: string,
    workTime: number,
    reservedNumber: number,
    availableNumber: number,
    amount: number,
    status: number,
    hosScheduleId: string
}
export type WordListDate = WordDate[]


export interface bookingScheduleListData {
    workDate: string,
    dayOfWeek: string,
    docCount: number,
    reservedNumber: number,
    availableNumber: number,
    active?: string
}

// 排班规则
export type WordRlueData = {
    total: number,
    bookingScheduleList: bookingScheduleListData[]
    baseMap: {
        hosname: string
    }
}
// 排班规则列表
// export type WordRlueListData = WordRlueData[]

// 定义分页列表的每一项数据
export type PageContentData = {
    id: string,
    isDeleted: number,
    param: paramInfoData
    hoscode: string,
    hosname: string,
    hostype: string,
    provinceCode: string,
    cityCode: string,
    districtCode: string,
    logoData: string,
    intro: string,
    status: number,
    bookingRule: BookingRuleDate
}
export type PageContentListData = PageContentData[]

// 定义分页列表的数据
export type PageListData = {
    content: PageContentListData
    pageable: {
        sort: {
            sorted: boolean,
            unsorted: boolean,
            empty: boolean
        },
        pageNumber: number,
        pageSize: number,
        offset: number,
        paged: boolean,
        unpaged: boolean
    },
    last: boolean,
    totalPages: number,
    totalElements: number,
    first: boolean,
    sort: {
        sorted: boolean,
        unsorted: boolean,
        empty: boolean
    },
    numberOfElements: number,
    size: number,
    number: number,
    empty: boolean
}

// 定义分页列表的请求参数类型
export interface PageInfoData {
    page: number,
    limit: number,
    hoscode?: string,
    depcode?: string,
    hosname?: string,
    hostype?: string,
    provinceCode?: string,
    cityCode?: string,
    districtCode?: string,
    status?: number | undefined | string
}


// 省,市,区数据对象类型
export interface IdictItem {
    id: string
    name: string
    value: string
}
export type IdictList = IdictItem[]

// 定义科室子类数据
interface PathologyChilder {
    depcode: string,
    depname: string,
    disabled?: boolean,
    key?: string,
    title?: string
}

// 定义科室数据
export interface PathologyData {
    depcode: string,
    depname: string,
    disabled?: boolean,
    children: PathologyChilder[],
    key?: string,
    title?: string
}

export type PathologyListData = PathologyData[]



export default {

    // GET /admin/hosp/hospital/show/{id}
    // 获取医院详情
    getHospitalDetail(id: number) {
        return request.get<any, HospitalDetailData>(`/admin/hosp/hospital/show/${id}`)
    },
    // GET /admin/hosp/hospital/updateStatus/{id}/{status}
    // 更新上线状态
    // 根据当前status改变当前上下线状态
    updateStatus({ id, status }: { id: string, status: number }) {
        return request.get<any, any>(`/admin/hosp/hospital/updateStatus/${id}/${status}`)
    },
    // GET /admin/hosp/hospital/{page}/{limit}
    // 获取分页列表
    getPageList({ page, limit, hoscode = '', depcode = '', hosname = '', hostype = '', provinceCode = '', cityCode = '', districtCode = '', status }: PageInfoData) {
        // 判断status是否有值
        if (status) {
            return request.get<any, PageListData>(`/admin/hosp/hospital/${page}/${limit}?hoscode=${hoscode}&depcode=${depcode}&hosname=${hosname}&hostype=${hostype}&provinceCode=${provinceCode}&cityCode=${cityCode}&districtCode=${districtCode}&status=${status}`)
        } else {
            return request.get<any, PageListData>(`/admin/hosp/hospital/${page}/${limit}?hoscode=${hoscode}&depcode=${depcode}&hosname=${hosname}&hostype=${hostype}&provinceCode=${provinceCode}&cityCode=${cityCode}&districtCode=${districtCode}`)
        }
    },

    // 获取排班
    // GET /admin/hosp/schedule/findScheduleList/{hoscode}/{depcode}/{workDate}
    // 获取workDate排班日期的排班详细列表
    getWordDate({ hoscode, depcode, workDate }: { hoscode: string, depcode: string, workDate: string }) {
        // console.log(hoscode, depcode, workDate);

        return request.get<any, WordListDate>(`/admin/hosp/schedule/findScheduleList/${hoscode}/${depcode}/${workDate}`)
    },
    // GET /admin/hosp/schedule/getScheduleRule/{page}/{limit}/{hoscode}/{depcode}
    // 获取排班规则数据
    getWordRlue({ page, limit, hoscode, depcode }: { page: number, limit: number, hoscode: string, depcode: string }) {
        return request.get<any, WordRlueData>(`/admin/hosp/schedule/getScheduleRule/${page}/${limit}/${hoscode}/${depcode}`)
    },

    // GET /admin/hosp/department/{hoscode}
    // 获取分页列表
    // 获取科室列表数据
    // getDepartmentList(hoscode: string) {
    //     return request.get<any,WordListDate>(`/admin/hosp/department/${hoscode}`)
    // },
    // GET /admin/hosp/department/{hoscode}
    // 获取科室分页列表
    getPathologyList(hoscode: string) {
        return request.get<any, PathologyListData>(`/admin/hosp/department/${hoscode}`)
    },
    // 获取省数据的函数
    reqProvinceList(dictCode: string = 'province') {
        return request.get<any, IdictList>(
            `/admin/cmn/dict/findByDictCode/${dictCode}`
        )
    },
    // 获取市或区或医院类型数据的函数
    reqCityOrDistrictList(parentId: string) {
        return request.get<any, IdictList>(
            `/admin/cmn/dict/findByParentId/${parentId}`
        )
    }
}
